We are happy to announce the release of SunPy 0.6 our biggest release yet! For a full list of all of the features in this release check out the CHANGELOG.md. Here is a quick rundown of some of the featured new capabilities.
plot_settings property.The rest of this document demonstrates some of these capabilities. This post is based on an ipython notebook which you can download yourself to test out and play around yourself.
In [1]:
# ipython settings
%matplotlib inline
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('pdf', 'svg')
In [2]:
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
mpl.rcParams['figure.figsize'] = (7, 7)
import warnings
warnings.filterwarnings("ignore")
In [3]:
import sunpy.data
sunpy.data.download_sample_data()
now when you import the sample data you should have all of the links to the files like before
In [3]:
import sunpy.data.sample
In [4]:
sunpy.data.sample.AIA_193_IMAGE
Out[4]:
for more info see the documentation
In [5]:
import astropy.units as u
from astropy.units import Quantity
from sunpy.sun.constants import au
from astropy.constants import c, k_B
In [6]:
5 * u.cm
Out[6]:
In [7]:
Quantity(3 * 10 ** 8, 'cm/s')
Out[7]:
In [8]:
from sunpy.map import Map
aia = Map(sunpy.data.sample.AIA_193_IMAGE)
In [9]:
aia.wavelength
Out[9]:
In [10]:
aia.wavelength.to('nm')
Out[10]:
In [11]:
aia.center
Out[11]:
In [12]:
aia.dimensions
Out[12]:
Pixels are a unit too!
In [13]:
aia.scale.x * 100 * u.pix
Out[13]:
Let's first convert from an angular size to a physical size
In [14]:
angular_conversion = np.sin(1 * u.arcsec) * au / u.arcsec
In [15]:
angular_conversion.to('km/arcsec')
Out[15]:
In [16]:
(aia.scale.x * 100 * u.pix * angular_conversion).to('Mm')
Out[16]:
Now let's try input. submap() now requires quantities as input
In [17]:
smap = aia.submap([400, 500] * u.arcsec, [-200, -300] * u.arcsec)
smap
Out[17]:
In [18]:
# time it takes for light to travel from the Sun to the Earth
dt = au / c
dt.to('min')
Out[18]:
Let's calculate the thermal energy associated with a flare (see this paper). Say you measured the angular size of the source and the temperature and the emission measure from the spectrum.
In [19]:
angular_size = 2.5 * u.arcsec
temperature = 19.7 * 10**6 * u.Kelvin
emission_measure = Quantity(0.2 * 10 ** 49, 'cm-3')
In [20]:
radius = 2.8 * u.arcsec * angular_conversion
And now let's calculate the volume assuming a sphere
In [21]:
volume = 4 * np.pi / 3 * radius ** 3
volume.to('cm3')
Out[21]:
Let's assume a filling factor of 1 and calculate the density of the source
In [22]:
filling_factor = 1
density = np.sqrt(filling_factor * emission_measure / volume)
density.decompose().cgs
Out[22]:
And now let's finally get the thermal energy
In [23]:
thermal_energy = 3 * k_B * temperature * np.sqrt(emission_measure * volume * filling_factor)
thermal_energy.decompose()
Out[23]:
But we want it in erg so let's convert to cgs
In [24]:
thermal_energy.cgs
Out[24]:
If we had made a mistake somewhere with our units for example giving the filling factor a unit of cm we would have gotten an error
In [25]:
filling_factor = 1 * u.cm
thermal_energy = 3 * k_B * temperature * np.sqrt(emission_measure * volume * filling_factor)
thermal_energy.to('erg')
Major updates throughout. Of course, this is most easily seen when browsing our documentation online but they are also useful reference when analyzing data. For example...
In [26]:
print(aia.__doc__)
You can also access it in your ipython notebook like so
In [ ]:
aia?
And here it is rendered on our documentation
This is availabe for all of the LightCurve objects. Here is just one example.
In [27]:
from sunpy import lightcurve as lc
from sunpy.time import TimeRange
goes = lc.GOESLightCurve.create(TimeRange('2012/06/01', '2012/06/05'))
In [28]:
print(goes.__doc__)
and here is it's doc string rendered in our documentation
SunPy provides default color tables and normalizations (this is how the data is scaled to be converted to a color, note that it does not touch the data). This is so that the user doesn't have to think about it. Unfortunately our default normalization was less than optimatl and would clip the brightest regions. We have fixed this by choosing custom normalizations for each data set with the philosophy that ALL data should be shown, from the dimmest to the brightest. Here are a few examples
In [29]:
aia = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)
aia.plot()
plt.colorbar()
plt.show()
In [30]:
aia = sunpy.map.Map(sunpy.data.sample.AIA_193_IMAGE)
aia.plot()
plt.colorbar()
plt.show()
Of course this does not always look great. For example,
In [31]:
aia = sunpy.map.Map(sunpy.data.sample.AIA_94_CUTOUT)
aia.plot()
plt.colorbar()
plt.show()
This is because
In [32]:
aia.min()
Out[32]:
In [33]:
aia.plot_settings
Out[33]:
In [34]:
norm = aia.plot_settings['norm']
In [35]:
norm.vmin = 0
In [36]:
aia.plot()
plt.colorbar()
Out[36]:
One more example
In [37]:
from matplotlib import colors
aia = Map(sunpy.data.sample.AIA_171_IMAGE)
fig = plt.figure(figsize=(5, 15))
ax1 = fig.add_subplot(3,1,1)
aia.plot()
plt.colorbar()
ax2 = fig.add_subplot(3,1,2)
# the sunpy color maps are now registered with matplotlib
aia.plot_settings['cmap'] = plt.get_cmap('sohoeit171')
aia.plot()
plt.colorbar()
ax3 = fig.add_subplot(3,1,3)
aia.plot_settings['norm'] = colors.LogNorm()
aia.plot()
fig.subplots_adjust(hspace=0.4)
plt.colorbar()
plt.show()
For more information check the plotting documentations